<template>
  <van-row>

    <van-row>
      <van-nav-bar left-arrow @click-left="$router.go(-1)" title="我的好友" left-text="返回">
      </van-nav-bar>
    </van-row>
    <van-row>
      <van-cell v-for="(item,index) in data" :key="index" size="large" is-link :to="'/chatmsg/'+item.id">
        <template #icon>
          <van-icon v-if="item.heardImgUrl" :name="item.heardImgUrl" size="30" />
          <van-icon v-else name="user-o" size="30"></van-icon>
        </template>
        <template #title>
          <label>{{item.name}}</label>
        </template>
      </van-cell>
    </van-row>
  </van-row>
</template>

<script>
  import {
    Button,
    Toast,
    Row,
    Col,
    NavBar,
    Icon,
    Cell,
  } from 'vant';
  export default {
    name: 'myfriends',
    components: {
      'van-button': Button,
      'van-row': Row,
      'van-col': Col,
      'van-nav-bar': NavBar,
      'van-icon': Icon,
      'van-cell': Cell
    },
    data: function () {
      return {
        data: [], //好友数据
      }
    },
    methods: {

      //加载我的好友信息
      async loadMyFriends() {
        var res = await this.$ajax.get(`/api/organization/${ this.$user.getOrganizationId()}/user`);
        if (res.status == 1) {
          Toast.fail(res.msg);
          return;
        }
        //不显示当前登录账号
        var userId = this.$user.getUserId();
        this.data = res.data.filter(a => a.id != userId);
      }
    },
    async mounted() {
      //加载好友数据
      await this.loadMyFriends();
      //显示底部栏
      this.$store.commit('updateShowFoot', false)
    }
  }

</script>

<style scoped>
  .van-cell--large .van-cell__title {
    margin-left: 15px;
  }

</style>
